﻿/// <reference path="../iuPlace.js" />
iuPlace.Api = {
    Types: {
        DataResult: {
            Data: null,
            Error: "",
            IsError: false
        },
        TypeContainer: {
            Browser: 0,
            Application: 1
        },
        TypeView: {
            Site: 0,
            Mobile: 1
        },
        Gender: {
            Male: 0,
            Female: 1
        },
        User: {
            Id: 0,
            UId: 0,
            UserName: "",
            Name: "",
            ProfileUrl: "",
            AccessToken: "",
            TokenSecret: "",
            Gender: 0,
            DateBirthDay: ""
        }
    },
    Session: {
        Identification: "",
        IsAuthenticated: false,
        User: {         
        },
        Container: {
            Type: 0,
            View: 0,
            Platform: ""
        }
    }
};

iuPlace.Api.Session.User = $.extend({}, iuPlace.Api.Types.User, {});

(function () {
    var obj = this;  
    
    function request(url, json, data, callback) {
        data = data == null ? null : (json ? JSON.stringify(data) : data);
        var contentType = json ? "application/json; charset=utf-8" : null;
        $.ajax({
            url: "Api/" + url,
            data: data,
            type: "post",
            dataType: "json",
            contentType: contentType,
            success: function (dataResult, textStatus, XMLHttpRequest) {
                if ($.isFunction(callback))
                    callback(dataResult);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                var dataResult = $.extend({}, iuPlace.Api.Types.DataResult, {});
                dataResult.IsError = true;
                dataResult.Error = "RequestApi";
                if ($.isFunction(callback))
                    callback(dataResult);
            }
        });
    };
      
    $.extend(iuPlace.Api, {
        Request: request
    });
})();